|
|
@@ -14,15 +14,16 @@ module Agents
|
14
|
14
|
|
15
|
15
|
You also must select `which_day` you would like to get the weather for where the number 0 is for today and 1 is for tomorrow and so on. Weather is only returned for 1 week at a time.
|
16
|
16
|
|
17
|
|
- The weather can be provided by either Wunderground or ForecastIO. To choose which `service` to use, enter either `forecastio` or `wunderground`.
|
|
17
|
+ The weather can be provided by either Wunderground or Dark Sky. To choose which `service` to use, enter either `darksky` or `wunderground`.
|
18
|
18
|
|
19
|
|
- The `location` can be a US zipcode, or any location that Wunderground supports. To find one, search [wunderground.com](http://wunderground.com) and copy the location part of the URL. For example, a result for San Francisco gives `http://www.wunderground.com/US/CA/San_Francisco.html` and London, England gives `http://www.wunderground.com/q/zmw:00000.1.03772`. The locations in each are `US/CA/San_Francisco` and `zmw:00000.1.03772`, respectively.
|
|
19
|
+ The `location` should be:
|
20
|
20
|
|
21
|
|
- If you plan on using ForecastIO, the `location` must be a comma-separated string of co-ordinates (longitude, latitude). For example, San Francisco would be `37.7771,-122.4196`.
|
|
21
|
+ * For Wunderground: A US zipcode, or any location that Wunderground supports. To find one, search [wunderground.com](http://wunderground.com) and copy the location part of the URL. For example, a result for San Francisco gives `http://www.wunderground.com/US/CA/San_Francisco.html` and London, England gives `http://www.wunderground.com/q/zmw:00000.1.03772`. The locations in each are `US/CA/San_Francisco` and `zmw:00000.1.03772`, respectively.
|
|
22
|
+ * For Dark Sky: `location` must be a comma-separated string of co-ordinates (longitude, latitude). For example, San Francisco would be `37.7771,-122.4196`.
|
22
|
23
|
|
23
|
24
|
You must setup an [API key for Wunderground](http://www.wunderground.com/weather/api/) in order to use this Agent with Wunderground.
|
24
|
25
|
|
25
|
|
- You must setup an [API key for Forecast](https://developer.forecast.io/) in order to use this Agent with ForecastIO.
|
|
26
|
+ You must setup an [API key for Dark Sky](https://darksky.net/dev/) in order to use this Agent with Dark Sky.
|
26
|
27
|
|
27
|
28
|
Set `expected_update_period_in_days` to the maximum amount of time that you'd expect to pass between Events being created by this Agent.
|
28
|
29
|
|
|
|
@@ -100,7 +101,7 @@ module Agents
|
100
|
101
|
end
|
101
|
102
|
|
102
|
103
|
def validate_options
|
103
|
|
- errors.add(:base, "service must be set to 'forecastio' or 'wunderground'") unless ["forecastio", "wunderground"].include?(weather_provider)
|
|
104
|
+ errors.add(:base, "service must be set to 'darksky' or 'wunderground'") unless %w[darksky forecastio wunderground].include?(weather_provider)
|
104
|
105
|
errors.add(:base, "location is required") unless location.present?
|
105
|
106
|
errors.add(:base, "api_key is required") unless interpolated['api_key'].present?
|
106
|
107
|
errors.add(:base, "which_day selection is required") unless which_day.present?
|
|
|
@@ -116,7 +117,7 @@ module Agents
|
116
|
117
|
end
|
117
|
118
|
end
|
118
|
119
|
|
119
|
|
- def forecastio
|
|
120
|
+ def dark_sky
|
120
|
121
|
if key_setup?
|
121
|
122
|
ForecastIO.api_key = interpolated['api_key']
|
122
|
123
|
lat, lng = location.split(',')
|
|
|
@@ -127,8 +128,8 @@ module Agents
|
127
|
128
|
def model(weather_provider,which_day)
|
128
|
129
|
if weather_provider == "wunderground"
|
129
|
130
|
wunderground[which_day]
|
130
|
|
- elsif weather_provider == "forecastio"
|
131
|
|
- forecastio.each do |value|
|
|
131
|
+ elsif weather_provider == "darksky" || weather_provider == "forecastio"
|
|
132
|
+ dark_sky.each do |value|
|
132
|
133
|
timestamp = Time.at(value.time)
|
133
|
134
|
if (timestamp.to_date - Time.now.to_date).to_i == which_day
|
134
|
135
|
day = {
|